<template>
  <view class="main">
		
		<view class="class_h bg-white" >
			<view class="top" @click="return_step">					
				<image src="../../../static/resource/back.png" mode="aspectFill" style="width: 74px;height: 30px;"></image>				
			</view>
			<text class="task_name">任务管理</text>
		</view>	
		<view class="task_main bg-white">
			<view class="flex blood_top">
				
				<view class="flex">
					<image src="/static/resource/blood_sugar.png" class="blood_sugar" v-if="blood_type ==1 " @click="select_blood(1)"></image>
					<image src="/static/resource/blood_sugar1.png" class="blood_pressure" v-if="blood_type ==2 " @click="select_blood(1)"></image>
				</view>
				<view class="flex ml-20">
					<image src="/static/resource/blood_pressure.png" class="blood_pressure" v-if="blood_type ==1 " @click="select_blood(2)"></image>
					<image src="/static/resource/blood_pressure1.png" class="blood_sugar" v-if="blood_type ==2 " @click="select_blood(2)"></image>
				</view>
				
			<!-- 	<view class="flex bg" @click="select_blood(1)" :class="[blood_type==1?'active':'']">
					 <view class="flex mb-15">
					 	 <image :src="[blood_type==1?'/static/resource/subtract_11.png':'/static/resource/subtract_1.png']" mode="aspectFill"  :class="[blood_type==1?'income_select':'income']"></image>
					 </view>
					 <view class="flex" :class="[blood_type==1?'active_text':'']">
					 	<text class="blood_text">血糖</text>
						<text class="blood_text">测量</text>
					 </view>
										 
				</view>
				<view class="flex bg" @click="select_blood(2)" :class="[blood_type==2?'active':'']">
					 <view class="flex mb-15">
					 	<image :src="[blood_type==2?'/static/resource/subtract_22.png':'/static/resource/subtract_2.png']" mode="aspectFill"  :class="[blood_type==2?'income_select':'income']"></image>
					 </view>
					 <view class="flex" :class="[blood_type==2?'active_text':'']">
					 	<text class="blood_text">血压</text>
					 	<text class="blood_text">测量</text>
					 </view>					 
				</view>
				<view class="flex bg" @click="select_blood(3)" :class="[blood_type==3?'active':'' ]">
					<view class="flex mb-15">
					 	<image :src="[blood_type==3?'/static/resource/subtract_33.png':'/static/resource/subtract_3.png']" mode="aspectFill"  :class="[blood_type==3?'income_select':'income']"></image>
					</view>
					<view class="flex" :class="[blood_type==3?'active_text':'']">
					    <text class="blood_text">运动</text>	
					</view>	
				</view>
				<view class="flex bg" @click="select_blood(4)" :class="[blood_type==4?'active':'']">
					 <view class="flex mb-15">
					 	<image :src="[blood_type==4?'/static/resource/subtract_44.png':'/static/resource/subtract_4.png']" mode="aspectFill"  :class="[blood_type==4?'income_select':'income']"></image>
					 </view>
					<view class="flex" :class="[blood_type==4?'active_text':'']">
					   <text class="blood_text">用药</text>
					</view>	
				</view> -->	
			</view>	
			
			<view style="flex" v-if="blood_type==1">
			    <calendar-sugar
				  :monthLabel="month"
			      :weekDays="weekDays"
			      :timeSlots="timeSlots"
			      :cells="cells"
			    />
			  </view>
			  
			<view style="flex" v-if="blood_type==2">
			     <calendar-pressure
				   :monthLabel="month"
			       :weekDays="weekDays"
			       :timeSlots="timeSlotssPre"
			       :cells="cellsPre"
			     />
			</view>
			
			<!-- 运动 -->
			<view class="flex flex-direction" v-if="blood_type==3">
				
				<view class="effect_title">
					<view class="flex justify-start align-center text-center">
						<view class="flex">
							<image src="../../../static/resource/foot.png" mode="aspectFill" style="width: 175px;height: 24px;"></image>
						</view>
					</view>	
				</view>
				
				<view class="left" >
					<view class="bubble-container">
						<text class="bubble">{{sbpData}}</text>	
						<text class="unit">步</text>	
					</view>				  
					<view class="ruler-box" style="margin-top: 60rpx;">
						<!-- 两边渐变遮罩 -->
						<view class="fade-left"></view>
						<view class="fade-right"></view>
						<!-- 横向可滑动刻度 -->
						<slide-choose :width="100" :bigItemWidth="2" :littleItemWidth="2" @change="chooseChange" height="130"
									:cellWidth="6" :cells="10" :cellNum="100" :startNum="800" :endNum="10600" color="#867f7f" :bigItemHeight="20"
									:littleItemHeight="10" selColor="#3484E6" bgColor="#efefef" align="flex-end" numPos="bottom" v-model="sbpData"></slide-choose>				
					 </view>	
				</view>
				
				<view class="flex submit_icon" @click="substep">
					 <image src="/static/resource/submit.png"  style="width: 343px;height: 44px;"></image>
				</view>				
			</view>
			
			<!-- 用药 -->
			<view class="flex flex-direction" v-if="blood_type==4">
				<view class="effect_title">
					<view class="flex flex-direction">
						<view class="flex">
							<image src="../../../static/resource/sugar—incon.png" mode="aspectFill" style="width: 175px;height: 24px;"></image>
						</view>
						
						 <view class="radio-group">
						    
							<radio-group v-model="selected_sugar" @change="onRadioChangeSugar">
							      <view class="radio-item" v-for="(item, index) in options_sugar" :key="index">
							        <radio :value="item" color="#007AFF" :checked="item === selected_sugar"></radio>
							        <text>{{ item }}</text>
							      </view>
							</radio-group>							
								
						  </view>						
					</view>	
				</view>				
				
				<view class="effect_title">
					<view class="flex flex-direction">
						<view class="flex">
							<image src="../../../static/resource/pressure—incon.png" mode="aspectFill" style="width: 175px;height: 24px;"></image>
						</view>
						
						<view class="radio-group">
						   <radio-group v-model="selected_pressure" @change="onRadioChangePressure">
						     <view class="radio-item" v-for="(item, index) in options_pressure" :key="index">
						       <radio :value="item" color="#007AFF" :checked="item === selected_pressure"></radio>
						       <text>{{ item }}</text>
						     </view>
						   </radio-group>
						 </view>
						
					</view>	
				</view>
				
				<view class="flex submit_icon" @click="submedication">
					 <image src="/static/resource/submit.png"  style="width: 343px;height: 44px;"></image>
				</view>					
			</view>
						  
		</view>
		
	   
  </view>
</template>

<script>
	import CalendarSugar    from '@/components/dui-line-chart/calendar-table-sugar.vue' //血糖
	import CalendarPressure   from '@/components/dui-line-chart/calendar-table-pressure.vue'
	import slideChoose from '@/components/dlm-slide-choose/dlm-slide-choose.vue'
	export default {
	    components: { 
			CalendarSugar,
		    CalendarPressure,
			slideChoose
		},
		data() {
			return {
				...getApp().globalData.config,		
				blood_type:1,
				month:'2025年11月',
				weekDays: [
					{ week:'周一', date:'13' },
					{ week:'周二', date:'14' },
					{ week:'周三', date:'15' },
					{ week:'周四', date:'16' },
					{ week:'周五', date:'17' },
					{ week:'周六', date:'18' },
					{ week:'周日', date:'19' }
				],
				timeSlots: ['凌晨','空腹','早餐后','午餐前','午餐后','晚餐前','晚餐后','睡前'],					  
				cells: [
					[ {status:1, srcStatus:1}, {status:1, srcStatus:1}, {status:0, srcStatus:0}, {status:0, srcStatus:0}, {status:1, srcStatus:1}, {status:0, srcStatus:0}, {status:0, srcStatus:0} ],
					[ {status:1, srcStatus:0}, {status:0, srcStatus:0}, {status:1, srcStatus:1}, {status:0, srcStatus:0}, {status:0, srcStatus:0}, {status:1, srcStatus:1}, {status:0, srcStatus:0} ],
					[ {status:1, srcStatus:1}, {status:0, srcStatus:0}, {status:0, srcStatus:0}, {status:1, srcStatus:1}, {status:0, srcStatus:0}, {status:0, srcStatus:0}, {status:1, srcStatus:0} ],
					[ {status:0, srcStatus:0}, {status:1, srcStatus:1}, {status:0, srcStatus:0}, {status:0, srcStatus:0}, {status:1, srcStatus:0}, {status:0, srcStatus:0}, {status:0, srcStatus:0} ],
					[ {status:1, srcStatus:1}, {status:0, srcStatus:0}, {status:0, srcStatus:0}, {status:0, srcStatus:0}, {status:0, srcStatus:0}, {status:1, srcStatus:1}, {status:0, srcStatus:0} ],
					[ {status:0, srcStatus:0}, {status:0, srcStatus:0}, {status:0, srcStatus:0}, {status:1, srcStatus:1}, {status:0, srcStatus:0}, {status:0, srcStatus:0}, {status:0, srcStatus:0} ],
					[ {status:0, srcStatus:0}, {status:0, srcStatus:0}, {status:1, srcStatus:1}, {status:0, srcStatus:0}, {status:0, srcStatus:0}, {status:0, srcStatus:0}, {status:0, srcStatus:0} ],
					[ {status:0, srcStatus:0}, {status:0, srcStatus:0}, {status:0, srcStatus:0}, {status:0, srcStatus:0}, {status:0, srcStatus:0}, {status:1, srcStatus:1}, {status:0, srcStatus:0} ]
				],
				timeSlotssPre:['清晨','白天','晚上'],
				cellsPre: [
					[ {status:1, srcStatus:1}, {status:1, srcStatus:1}, {status:1, srcStatus:1}, {status:0, srcStatus:0}, {status:1, srcStatus:1}, {status:0, srcStatus:0}, {status:0, srcStatus:0} ],
					[ {status:1, srcStatus:0}, {status:0, srcStatus:0}, {status:1, srcStatus:1}, {status:0, srcStatus:0}, {status:0, srcStatus:0}, {status:1, srcStatus:1}, {status:0, srcStatus:0} ],
					[ {status:1, srcStatus:1}, {status:0, srcStatus:0}, {status:0, srcStatus:0}, {status:1, srcStatus:1}, {status:0, srcStatus:0}, {status:0, srcStatus:0}, {status:1, srcStatus:0} ]
				],
				sbpData:5300,
				selected_sugar: '无需', // 糖
				selected_pressure:'无需',
				options_sugar: ['无需', '一日一次', '一日两次', '一日三次'],
				options_pressure: ['无需', '一日一次', '一日两次', '一日三次'],
				user_info:{}
			}			
		},
		
		onShow() {
			this.user_info=uni.getStorageSync('userInfo');			
			this.query_index()
			
		}, 		
		methods: {
			...getApp().globalData.funcion,
			//设置步数
			substep(){
				let that=this
				let obj_data={
					token:this.user_info.token,
					motion_value:this.sbpData //
				};
				this.$http.doMotion(obj_data).then(res=>{
					if (res.resCode == '9999') {
					    uni.showToast({title:res.resMessage,icon:"success"})
					}else{
						uni.showToast({title:res.resMessage,icon:"error"})
					}
				})				
			},
			//设置用药
			submedication(){
				let that=this
				let obj_data={
					token:this.user_info.token,
					sugar_value:this.selected_sugar,
					pressure_value:this.selected_pressure 
				};
				this.$http.doMedication(obj_data).then(res=>{
					if (res.resCode == '9999') {
					    uni.showToast({title:res.resMessage,icon:"success"})
					}else{
						uni.showToast({title:res.resMessage,icon:"error"})
					}
				})	
			},			
			query_index(){
				let that=this
				let obj_data={
					token:this.user_info.token,
					blood_type:this.blood_type
				};
				this.$http.getTask(obj_data).then(res=>{
					if(res.resCode=='9999'){
						if(obj_data.blood_type==1){
							that.month=res.data.month
							that.weekDays=res.data.weekDays,
							that.timeSlots=res.data.timeSlots
							that.cells=res.data.cells
						}else{
							that.month=res.data.month
							that.weekDays=res.data.weekDays,
							that.timeSlotssPre=res.data.timeSlots
							that.cellsPre=res.data.cells
						}
					}				
				})	
			},
			select_blood(type){
				this.blood_type=type
				if(type==1 || type==2 ) this.query_index()
			},
			chooseChange(e) {
				console.log(e)
			},
			
			onRadioChangeSugar(e) {
			      // e.detail.value 是选中的值
			      console.log('当前选中:', e.detail.value);
			      // 可以在这里做其他操作
			    this.selected_sugar=e.detail.value
			},
			onRadioChangePressure(e) {
			      // e.detail.value 是选中的值
			      console.log('当前选中:', e.detail.value);
			      // 可以在这里做其他操作
			    this.selected_pressure=e.detail.value
			},
			//返回第一页
			return_step(){
				this.$routers.router('/pages/clock/index','switchTab') 
			},
			
			
		}
	  
	};
</script>

<style scoped>
  @import "./index.css";
</style>
